

using System;
using System.Data;
using System.Text;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using PuntoMascotasWeb.BackEnd.BE;

namespace PuntoMascotasWeb.BackEnd.DAC
{
  /// <summary>
  /// TableDataGateway para Usuarios.
  /// </summary>
  /// <Date>2013-06-09T14:58:01</Date>
  /// <Author>Mx23</Author>
  public class UsuariosDAC
  {
    /// <summary>
    /// Insert
    /// </summary>
    /// <param name="pUsuariosBE">UsuariosBE</param>
    /// <returns>void</returns>
    /// <Date>2013-06-09T14:58:01</Date>
    /// <Author>Mx23</Author>
    public static void Insert(UsuariosBE pUsuariosBE)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Usuarios_i");

        /// Id
        wDataBase.AddOutParameter(wCmd, "Id", System.Data.DbType.Int32, 4);
        /// Usuario
        wDataBase.AddInParameter(wCmd, "Usuario", System.Data.DbType.String, pUsuariosBE.Usuario);
        /// Password
        wDataBase.AddInParameter(wCmd, "Password", System.Data.DbType.String, pUsuariosBE.Password);
        /// IdRol
        wDataBase.AddInParameter(wCmd, "IdRol", System.Data.DbType.Int32, pUsuariosBE.IdRol);

        wDataBase.ExecuteNonQuery(wCmd);
        pUsuariosBE.Id = (System.Int32)wDataBase.GetParameterValue(wCmd, "Id");
      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// Update
    /// </summary>
    /// <param name="pUsuariosBE">UsuariosBE</param>
    /// <returns>void</returns>
    /// <Date>2013-06-09T14:58:01</Date>
    /// <Author>Mx23</Author>
    public static void Update(UsuariosBE pUsuariosBE)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Usuarios_u");

        /// Id
        wDataBase.AddInParameter(wCmd, "Id", System.Data.DbType.Int32, pUsuariosBE.Id);
        /// Usuario
        wDataBase.AddInParameter(wCmd, "Usuario", System.Data.DbType.String, pUsuariosBE.Usuario);
        /// Password
        wDataBase.AddInParameter(wCmd, "Password", System.Data.DbType.String, pUsuariosBE.Password);
        /// IdRol
        wDataBase.AddInParameter(wCmd, "IdRol", System.Data.DbType.Int32, pUsuariosBE.IdRol);

        wDataBase.ExecuteNonQuery(wCmd);

      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// Delete
    /// </summary>
    /// <param name="pId">Id</param>
    /// <returns>void</returns>
    /// <Date>2013-06-09T14:58:01</Date>
    /// <Author>Mx23</Author>
    public static void Delete(System.Int32 pId)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Usuarios_d");

        /// Id
        wDataBase.AddInParameter(wCmd, "Id", System.Data.DbType.Int32, pId);

        wDataBase.ExecuteNonQuery(wCmd);

      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// GetAll
    /// </summary>

    /// <returns>DataSet</returns>
    /// <Date>2013-06-09T14:58:01</Date>
    /// <Author>Mx23</Author>
    public static DataSet GetAll()
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Usuarios_s");


        return wDataBase.ExecuteDataSet(wCmd);
      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// GetByParam
    /// </summary>
    /// <param name="pUsuariosBE">UsuariosBE</param>
    /// <returns>DataSet</returns>
    /// <Date>2013-06-09T14:58:01</Date>
    /// <Author>Mx23</Author>
    public static DataSet GetByParam(UsuariosBE pUsuariosBE)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Usuarios_g");

        /// Id
        wDataBase.AddInParameter(wCmd, "Id", System.Data.DbType.Int32, pUsuariosBE.Id);
        /// Usuario
        wDataBase.AddInParameter(wCmd, "Usuario", System.Data.DbType.String, pUsuariosBE.Usuario);
        /// Password
        wDataBase.AddInParameter(wCmd, "Password", System.Data.DbType.String, pUsuariosBE.Password);
        /// IdRol
        wDataBase.AddInParameter(wCmd, "IdRol", System.Data.DbType.Int32, pUsuariosBE.IdRol);

        return wDataBase.ExecuteDataSet(wCmd);
      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }
  }
}